package org.lex.ftp.ui.speed;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import org.lex.awt.SystemClipboard;
import org.lex.ftp.FTP;
import org.lex.net.ftp.FTPURL;


public class TablePopupMenu extends JPopupMenu implements ActionListener {
	static final String OpenAC = "Open";
	static final String RemoveAC = "Remove";
	static final String RemoveSelectedAC = "Remove Selected";
	static final String CopyURLAC = "Copy URL";
	static final String PropertyAC = "Property";
	private SpeedPane pane = null;

	public TablePopupMenu(SpeedPane pane) {
		super();
		this.pane = pane;
		this.add(createMenuItem(OpenAC));
		this.add(createMenuItem(RemoveAC));
		this.add(createMenuItem(RemoveSelectedAC));
		this.addSeparator();
		this.add(this.createMenuItem(CopyURLAC));
		this.add(createMenuItem(PropertyAC));
	}

	private JMenuItem createMenuItem(String actionCommand) {
		JMenuItem menu = new JMenuItem(actionCommand);
		menu.setActionCommand(actionCommand);
		menu.addActionListener(this);
		return menu;
	}

	public void actionPerformed(ActionEvent e) {
		String ac = e.getActionCommand();
		if (OpenAC == ac) {
			FTPURL url = pane.getSelectedUrl();
			if (null != url)
				FTP.getApplication().getContentPane().open(url);
		} else if (RemoveAC == ac) {
		} else if (RemoveSelectedAC == ac) {
		} else if (CopyURLAC == ac) {
			FTPURL url = pane.getSelectedUrl();
			SystemClipboard.setClipboardContents(url.toString());

		} else if (PropertyAC == ac) {
		}
	}
}
